<!--
 * @Author: 迷洛洛ywc
 * @Date: 2024-04-15 13:05:31
 * @LastEditors: 迷洛洛ywc
 * @LastEditTime: 2024-05-06 15:15:45
 * @Description: 采收弹窗组件
-->
<template>
  <div class="seedAdd">
    <div class="routeName">采收</div>
    <el-form
      :model="pickForm"
      ref="pickForm"
      :rules="rules"
      label-width="100px"
      class="demo-ruleForm mt20 errorForm"
    >
    <el-form-item class="noRequire" label="*采收重量：" prop="num">
      <el-input class="widthInput widthSuffix" :min="0" type="number" v-model="pickForm.num" placeholder="请输入采收重量">
        <template #suffix>
          <div class="suffixText">公斤</div>
        </template>
      </el-input>
    </el-form-item>
    <el-form-item label="*种类：" prop="plantingVariety">
      <span class="greyColor">{{ $route.query.plantingVariety }}</span>
    </el-form-item>
    <el-form-item class="noRequire" label="*采收时间："  prop="time">
      <el-date-picker
        class="widthInput"
        v-model="pickForm.time"
        type="date"
        placeholder="选择日期"
        format="yyyy-MM-dd"
        value-format="yyyy-MM-dd"
      >
      </el-date-picker>
    </el-form-item>
      <el-form-item class="noRequire" label="*作业方式：" prop="way">
        <!-- <el-radio-group v-model="pickForm.way">
          <el-radio :label="'0'">人工</el-radio>
          <el-radio :label="'1'">机械</el-radio>
        </el-radio-group> -->
        <el-button
          class="typeBtn"
          :class="pickForm.way === '0' && 'checkBoxAll'"
          @click="pickForm.way = '0'"
        >
          人工
        </el-button>
        <el-button
          class="typeBtn"
          :class="pickForm.way === '1' && 'checkBoxAll'"
          @click="pickForm.way = '1'"
        >
          机械
        </el-button>
      </el-form-item>
      <el-form-item class="noRequire" label="*操作人：" prop="participantsId">
        <el-select v-model="pickForm.participantsId" class="widthInput"  placeholder="请选择操作人">
          <el-option
            v-for="item in userList"
            :key="item.userId"
            :label="item.name"
            :value="item.userId"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <!-- <el-form-item class="submitItem">
        <el-button type="primary" class="submitBtn" @click="submitForm('pickForm')"
          >立即创建</el-button
        >
      </el-form-item> -->
    </el-form>
    <div class="submitBottom">
      <el-button
        size="small"
        class="editBtn editBtnNone"
        @click="back()"
        >取消</el-button
      >
      <el-button
        class="editBtn"
        type="primary"
        size="small"
        @click="submitForm('pickForm')"
      >
        确定
      </el-button>
    </div>
  </div>
</template>

<script>
import { addArgiMissionApi } from '@/api/mission'
import { getUserListApi } from '@/api/dict'
export default {
  name: 'SevencolorUserFarmStockDialog',
  props: {
    // userList: {
    //   type: Array
    // }
  },

  data () {
    return {
      pickForm: {
        code: 'NS_CZ',
        baseId: 1,
        landId: null,
        way: '',
        num: null
      },
      rules: {
        way: [
          { required: true, message: '请选择作业方式', trigger: 'change' }
        ],
        participantsId: [
          { required: true, message: '请选择操作人', trigger: 'change' }
        ],
        time: [
          { required: true, message: '请选择时间', trigger: 'change' }
        ],
        num: [
          { required: true, message: '请填写采收数量', trigger: 'change' }
        ]
      },
      userList: []
    }
  },

  mounted () {
    this.pickForm.baseId = +this.$route.query.baseId
    this.pickForm.landId = +this.$route.query.landId
    this.getSysSeed()
  },

  methods: {
    // 返回
    back () {
      this.$router.go(-1)
    },
    // 播种字典表
    async getSysSeed () {
      const res = await getUserListApi(this.pickForm.baseId)
      // console.log(res2)
      this.userList = res.data
    },
    submitForm (formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          this.pickForm.num = +this.pickForm.num
          await addArgiMissionApi(this.pickForm)
          this.$router.go(-1)
        }
      })
    }
  }

}
</script>
<style lang="scss" scoped>
.active {
  border: 1px solid #64c3a4 !important;
  background: url("../../../assets/img/selected-ico.png") no-repeat right 3.7vw;
}
.seedAdd {
}
.input {
  width: 22.8vw;
}
.more {
   margin: 1vw 0;
   text-align: center;
}
.submitBtn {
  width: 5vw;
  margin: 0 6vw;
}
</style>
